// app/service/user.js
const Service = require('egg').Service;

class StepService extends Service {
  async muticreate(steparr, project_id) {
    const { ctx } = this;
    const steparrs = steparr?.map((it, i) => ({
      ...it,
      project_id,
      sort: i,
    }));
    let step;
    try {
      step = await ctx.model.Step.bulkCreate(steparrs);
    } catch (error) {
      step = error;
    }
    return step;
  }

  async getbyproject_id(project_id) {
    const { ctx } = this;
    const where = {
      project_id,
    };
    let step;
    try {
      step = await ctx.model.Step.findAll({
        where,
      });
    } catch (error) {
      step = error;
    }
    return step;
  }
}

module.exports = StepService;
